const user = require('../models/user')

// 用户登录
const userlogin = async function(ctx) {
  console.log(ctx.request.body);
  // 接收前端传递参数
  const data = {
    stuName: ctx.request.body.stuName,
    stuPwd: ctx.request.body.stuPwd,
  }
  try {
    const userInfo = await user.login(data);
    const resData =  userInfo.dataValues;
    const userToken = {
        stuNum: resData.stuNum,
        id: resData.id
    }
    const secret = 'admin';
    // const token = jwt.sign(userToken,secret);
    ctx.body = {
        code: 20000,
        data: {
          token: secret,
          info: userInfo.dataValues
        }
    }
  }
  catch(error) {
    ctx.body = {
        code: 40000,
        info: '未找到'
    }
    console.error(error);
  }
}

// 注销功能

const userlogout = async function(ctx) {
    ctx.body = {
      code: 20000,
      info: '注销成功'
    }
}

const getGoodsList = async function(ctx) {
    const result = await user.getGoodsList()
    return result;
}
module.exports = {
    userlogin,
    getGoodsList,
    userlogout
}